package imanager.showcases.agenda.client;

import com.googlecode.imanager.client.Container;
import com.googlecode.imanager.client.Panel;
import com.googlecode.imanager.client.action.DisplayAction;
import com.googlecode.imanager.client.event.EvaluationPhase;
import com.googlecode.imanager.client.event.PhaseEvent;
import com.googlecode.imanager.client.form.Button;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class ListaComprasFooter extends Panel {

    private static final long serialVersionUID = 1L;

    protected Button dadosClienteButton;
    protected Button exportarPdfButton;
    protected Button exportarXlsButton;
    protected Button cancelarButton;
    
    public ListaComprasFooter() {
        setSize(600, 40);
        createControls();
    }

    public ListaComprasFooter(Container parent) {
        this();
        setParent(parent);
    }
    
    private void createControls() {
        dadosClienteButton = new Button(this);
        exportarXlsButton = new Button(this);
        exportarPdfButton = new Button(this);
        cancelarButton = new Button(this);
        
        dadosClienteButton.setBounds(10, 10, 130, 20);
        dadosClienteButton.setText("Exibir Cliente");
        
        exportarXlsButton.setLeftTop(150, 10);
        exportarXlsButton.setWidth(130);
        exportarXlsButton.setText("Exportar Xls");

        exportarPdfButton.setLeftTop(290, 10);
        exportarPdfButton.setWidth(130);
        exportarPdfButton.setText("Exportar Pdf");

        cancelarButton.setLeftTop(430, 10);
        cancelarButton.setWidth(130);
        cancelarButton.setText("Cancelar");
    }

    @Override
    protected void onPhaseEvent(PhaseEvent e) {
        super.onPhaseEvent(e);
        
        // FIXME usar if (type==DOCUMENT_START) gera um erro

        if (e.getEventType() == EvaluationPhase.DOCUMENT_START){
            
            if (getImplementationType().isRunnable()){
                AgendaApplication app = (AgendaApplication) e.getApplication();

                dadosClienteButton.setAction(new DisplayAction(
                        app.getCadastroEntidadeDocument(), true));

                exportarXlsButton.setAction(app.getExportarXlsAction());
                exportarPdfButton.setAction(app.getExportarPdfAction());
                cancelarButton.setAction(new DisplayAction(getRootDocument(), false));
            }
        }
    }

    public Button getDadosClienteButton() {
        return dadosClienteButton;
    }

    public Button getExportarPdfButton() {
        return exportarPdfButton;
    }

    public Button getExportarXlsButton() {
        return exportarXlsButton;
    }

    public Button getCancelarButton() {
        return cancelarButton;
    }

}
